package cn.ffcs.uec.view.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.staffAndOutStaff.vo.StaffAndOutStaff;
import cn.ffcs.uec.view.dao.UecImportantWorkDao;
import cn.ffcs.uec.view.model.UecImportantWork;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecImportantDao")
@Transactional
public class UecImportantWorkDaoImpl extends BaseDaoImpl implements UecImportantWorkDao {

	@Override
	public PageInfo queryPageInfoByUecImportant(UecImportantWork uecImportant,
			int current, int pageSize) {
		if (null != uecImportant) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_IMPORTANT_WORK T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);

			if (!StrUtil.isNullOrEmpty(uecImportant.getPkPsndoc())) {
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecImportant.getPkPsndoc());
			}
			sb.append(" order by T.joindate");
			System.out.println("sb-----------"+sb.toString());
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecImportantWork.class);
		}
		return null;
	}

	@Override
	public UecImportantWork findUecImportantById(UecImportantWork uecImportantWork) {
		if (null != uecImportantWork) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_IMPORTANT_WORK T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			if (!StrUtil.isNullOrEmpty(uecImportantWork.getImportantId())) {
				sb.append(" AND T.IMPORTANT_ID = ? ");
				params.add(uecImportantWork.getImportantId());
			}
			List<UecImportantWork> uecEncs = this.jdbcFindList(sb.toString(), params,
					UecImportantWork.class);
			if (uecEncs.size() > 0) {
				return uecEncs.get(0);
			} 
		}
		return null;
	}

/**
 * 近三年情况
 */
	@Override
	public List<UecImportantWork> findUecImportantByPkPsndocAndDiffDate(StaffAndOutStaff staffAndOutStaff,String joinType) {
		if (null != staffAndOutStaff) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_IMPORTANT_WORK T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
			if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getPkPsndoc())) {
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(staffAndOutStaff.getPkPsndoc());
			}
			if(!StrUtil.isNullOrEmpty(joinType)) {
				sb.append(" AND T.jointype = ? ");
				params.add(joinType);
			}
			sb.append(" order by T.joindate ");	
			return this.jdbcFindList(sb.toString(), params, UecImportantWork.class);
		}
		return null;
	}

@Override
public List<UecImportantWork> findUecImportantByPkPsndoc(StaffAndOutStaff staffAndOutStaff,String joinType) {
	if (null != staffAndOutStaff) {
		StringBuilder sb = new StringBuilder(
				" SELECT * FROM UEC_IMPORTANT_WORK T WHERE 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		sb.append(" AND T.STATUS_CD = ? ");
		params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
		if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getPkPsndoc())) {
			sb.append(" AND T.PK_PSNDOC = ? ");
			params.add(staffAndOutStaff.getPkPsndoc());
		}
		if(!StrUtil.isNullOrEmpty(joinType)) {
			sb.append(" AND T.jointype = ? ");
			params.add(joinType);
		}
		sb.append(" order by T.joindate ");	
		return this.jdbcFindList(sb.toString(), params, UecImportantWork.class);
	}
	return null;
}

}
